package com.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.entity.Prescriptiondetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
@Mapper
public interface PrescriptiondetailrMapper extends BaseMapper<Prescriptiondetail> {
    @Select("SELECT prescription_detail_id, patient_name, start_date, end_date, cost, prescriptiondetail.state FROM prescriptiondetail, prescription, visit, patient WHERE prescriptiondetail.prescription_id = prescription.prescription_id AND prescription.visit_id = visit.visit_id AND visit.patient_id = patient.patient_id")
    List<Map<String, Object>> liquidation();

    @Update("UPDATE prescriptiondetail set state = '已结算' where prescription_detail_id = #{id}")
    void updateP(int id);

    @Select("SELECT prescription_detail_id, patient_name, a_date, daily_cost FROM dailydrugexpense, visit, patient WHERE dailydrugexpense.visit_id = visit.visit_id and visit.patient_id = patient.patient_id and dailydrugexpense.prescription_detail_id = #{id}")
    List<Map<String, Object>> getDaily(int id);

    @Select("SELECT drug_name, quantity, price, daily_price FROM usedrug,drug WHERE usedrug.`drug_id`=drug.drug_id AND prescription_detail_id=#{id}")
    List<Map<String, Object>> getDailyDrug(int id);
}
